package com.dubbo.regulate.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.dubbo.common.dtos.PageResponseResult;
import com.dubbo.common.dtos.ResponseResult;
import com.dubbo.model.regulate.dtos.RegCatalogDto;
import com.dubbo.model.regulate.pojos.RegCatalog;
import com.dubbo.model.regulate.pojos.RegProduct;
import com.dubbo.regulate.mapper.SonCatalogMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Service
@Component
public class SonCatalogService implements com.dubbo.regulate.SonCatalogService {
    @Autowired
    private SonCatalogMapper sonCatalogMapper;

    @Override
    public ResponseResult<List<RegCatalog>> ParentsCatalogList(RegCatalogDto dto) {
        //设置页码大小
        dto.checkParam();
        Integer page = dto.getPage();
        dto.setPage((page - 1) * dto.getSize());

        Integer count = sonCatalogMapper.count();//查询总条数
        List<RegCatalog> regCatalogs = sonCatalogMapper.parentsCatalogList(dto);

        PageResponseResult pageResponseResult = new PageResponseResult(page, dto.getSize(), count);
        pageResponseResult.setData(regCatalogs);

        return pageResponseResult;
    }
}
